package com.it.taoyidian.controller;

import com.it.taoyidian.entity.ResponseResult;
import com.it.taoyidian.entity.ResultEnum;
import com.it.taoyidian.entity.UserEntity;
import com.it.taoyidian.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@Slf4j
public class UserController {
    @Autowired
    @Qualifier("userService")
    private IUserService userService;

    @RequestMapping ("/home/login")
    public @ResponseBody ResponseResult login(String password, String phone) {
        UserEntity user=userService.login(password,phone);
        if(user!=null){
          if(user.getUser_type()==1){
              return ResponseResult.success("user_role");
          }else{
              return ResponseResult.success("admin_role");
          }
        }

        return ResponseResult.fail(ResultEnum.LOGIN_PHONE_PWD_ERROR);
    }
}
